package com.rfid.afd.presenter;

import android.os.Handler;

import com.rfid.afd.activity.view.ISearchView;
import com.rfid.afd.model.DeleteModel;
import com.rfid.afd.model.SearchModel;
import com.rfid.db.bean.Rfid;
import com.rfid.util.DBManager;
import com.rfid.util.RfidManager;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SearchPresenter extends BasePresenter<ISearchView>{


    SearchModel mSearchModel;
    protected ExecutorService mExecutor;
    protected Handler mHandler;

    public SearchPresenter() {
        mHandler = new Handler();
        mExecutor = Executors.newSingleThreadExecutor();
        mSearchModel = new SearchModel();
    }

    public void queryRfidsByBookNameOrBarCode(String name) {
        mIview.showLoading();
        mExecutor.execute(new Runnable() {
            @Override
            public void run() {
                List<Rfid> data = mSearchModel.getRfidsByBookNameOrBarCode(name);
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mIview.stopLoading();
                        mIview.onRfidsByBookName(data);
                    }
                });
            }
        });
    }


//    public void startScanRfid() {
//        mSearchModel.startScan();
//    }
//
//    public void stopScanRfid() {
//        mSearchModel.stopScan();
//    }
}
